package com.chatdating.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chatdating.entity.Like;
import com.chatdating.mapper.LikeMapper;
import com.chatdating.service.LikeService;
import org.springframework.stereotype.Service;

@Service
public class LikeServiceImpl extends ServiceImpl<LikeMapper, Like> implements LikeService {
    @Override
    public int getLikeCount(Long postId) {
        return baseMapper.countByPostId(postId);
    }

    @Override
    public void likePost(Long postId, Integer userId) {
        Like like = new Like();
        like.setPostId(postId);
        like.setUserId(userId);
        baseMapper.insert(like);
    }

    @Override
    public void unlikePost(Long postId, Integer userId) {
        baseMapper.deleteByPostAndUser(postId, userId);
    }
}
